package com.neusoft.elm.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.neusoft.elm.dao.AdminDao;
import com.neusoft.elm.po.Admin;
import com.neusoft.elm.util.DBUtil;

public class AdminDaoImpl  implements AdminDao{
	 Connection con = null;
	 PreparedStatement pst = null;
	 ResultSet rs = null;
	 
	@Override
	public Admin getAdminByNameByPass(String adminName, String password) {
		Admin admin=null;//初始化
	String sql = "SELECT * FROM admin WHERE adminName = ? AND password = ?";
		//1链接数据库
		
		try {
			con= DBUtil.getConnection();//接一下数据库 本来在try外面 直接扔里面
			pst=con.prepareStatement(sql);
			pst.setString(1,adminName);
			pst.setString(2, password);
			rs=pst.executeQuery();//结果集rs接收一下 ，下一步是结果集的遍历
			while(rs.next()){
				admin =new Admin();
				admin.setAdminId(rs.getInt("adminId"));//去数据库粘贴
				admin.setAdminName(rs.getString("adminName"));
				admin.setPassword(rs.getString("password"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}//发送sql语句
		finally{//资源的释放
			DBUtil.close(rs, pst, con);
			
		}
		return admin;   //admin返回null  记得写
	}

}
